home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_emacs.idb / usr / freeware / share / emacs / 19.34 / lisp / sendmail.el.z / sendmail.el
Encoding:
Text File  |  1998-10-28  |  39.4 KB  |  1,104 lines

  1. ;;; sendmail.el --- mail sending commands for Emacs.
  2.  
  3. ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6. ;; Keywords: mail
  7.  
  8. ;; This file is part of GNU Emacs.
  9.  
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ;; GNU General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  22. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. ;; Boston, MA 02111-1307, USA.
  24.  
  25. ;;; Commentary:
  26.  
  27. ;; This mode provides mail-sending facilities from within Emacs.  It is
  28. ;; documented in the Emacs user's manual.
  29.  
  30. ;;; Code:
  31.  
  32. ;;;###autoload
  33. (defvar mail-from-style 'angles "\
  34. *Specifies how \"From:\" fields look.
  35.  
  36. If `nil', they contain just the return address like:
  37.     king@grassland.com
  38. If `parens', they look like:
  39.     king@grassland.com (Elvis Parsley)
  40. If `angles', they look like:
  41.     Elvis Parsley <king@grassland.com>")
  42.  
  43. ;;;###autoload
  44. (defvar mail-self-blind nil "\
  45. Non-nil means insert BCC to self in messages to be sent.
  46. This is done when the message is initialized,
  47. so you can remove or alter the BCC field to override the default.")
  48.  
  49. ;;;###autoload
  50. (defvar mail-interactive nil "\
  51. Non-nil means when sending a message wait for and display errors.
  52. nil means let mailer mail back a message to report errors.")
  53.  
  54. ;;;###autoload
  55. (defvar mail-yank-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^remailed\\|^received:\\|^message-id:\\|^summary-line:\\|^to:\\|^subject:\\|^in-reply-to:\\|^return-path:" "\
  56. Delete these headers from old message when it's inserted in a reply.")
  57.  
  58. ;; Useful to set in site-init.el
  59. ;;;###autoload
  60. (defvar send-mail-function 'sendmail-send-it "\
  61. Function to call to send the current buffer as mail.
  62. The headers should be delimited by a line whose contents
  63. match the variable `mail-header-separator'.")
  64.  
  65. ;;;###autoload
  66. (defvar mail-header-separator "--text follows this line--" "\
  67. *Line used to separate headers from text in messages being composed.")
  68.  
  69. ;; Set up mail-header-separator for use as a category text property.
  70. (put 'mail-header-separator 'rear-nonsticky '(category))
  71. ;;; This was a nice idea, for preventing accidental modification of
  72. ;;; the separator.   But I found it also prevented or obstructed
  73. ;;; certain deliberate operations, such as copying the separator line
  74. ;;; up to the top to send myself a copy of an already sent outgoing message
  75. ;;; and other things.  So I turned it off.  --rms.
  76. ;;;(put 'mail-header-separator 'read-only t)
  77.  
  78. ;;;###autoload
  79. (defvar mail-archive-file-name nil "\
  80. *Name of file to write all outgoing messages in, or nil for none.
  81. This can be an inbox file or an Rmail file.")
  82.  
  83. ;;;###autoload
  84. (defvar mail-default-reply-to nil
  85.   "*Address to insert as default Reply-to field of outgoing messages.
  86. If nil, it will be initialized from the REPLYTO environment variable
  87. when you first send mail.")
  88.  
  89. ;;;###autoload
  90. (defvar mail-alias-file nil
  91.   "*If non-nil, the name of a file to use instead of `/usr/lib/aliases'.
  92. This file defines aliases to be expanded by the mailer; this is a different
  93. feature from that of defining aliases in `.mailrc' to be expanded in Emacs.
  94. This variable has no effect unless your system uses sendmail as its mailer.")
  95.  
  96. ;;;###autoload
  97. (defvar mail-personal-alias-file "~/.mailrc"
  98.   "*If non-nil, the name of the user's personal mail alias file.
  99. This file typically should be in same format as the `.mailrc' file used by
  100. the `Mail' or `mailx' program.
  101. This file need not actually exist.")
  102.  
  103. (defvar mail-setup-hook nil
  104.   "Normal hook, run each time a new outgoing mail message is initialized.
  105. The function `mail-setup' runs this hook.")
  106.  
  107. (defvar mail-aliases t
  108.   "Alist of mail address aliases,
  109. or t meaning should be initialized from your mail aliases file.
  110. \(The file's name is normally `~/.mailrc', but your MAILRC environment
  111. variable can override that name.)
  112. The alias definitions in the file have this form:
  113.     alias ALIAS MEANING")
  114.  
  115. (defvar mail-alias-modtime nil
  116.   "The modification time of your mail alias file when it was last examined.")
  117.  
  118. (defvar mail-yank-prefix nil
  119.   "*Prefix insert on lines of yanked message being replied to.
  120. nil means use indentation.")
  121. (defvar mail-indentation-spaces 3
  122.   "*Number of spaces to insert at the beginning of each cited line.
  123. Used by `mail-yank-original' via `mail-yank-cite'.")
  124. (defvar mail-yank-hooks nil
  125.   "Obsolete hook for modifying a citation just inserted in the mail buffer.
  126. Each hook function can find the citation between (point) and (mark t).
  127. And each hook function should leave point and mark around the citation
  128. text as modified.
  129.  
  130. This is a normal hook, misnamed for historical reasons.
  131. It is semi-obsolete and mail agents should no longer use it.")
  132.  
  133. (defvar mail-citation-hook nil
  134.   "*Hook for modifying a citation just inserted in the mail buffer.
  135. Each hook function can find the citation between (point) and (mark t).
  136. And each hook function should leave point and mark around the citation
  137. text as modified.
  138.  
  139. If this hook is entirely empty (nil), a default action is taken
  140. instead of no action.")
  141.  
  142. (defvar mail-abbrevs-loaded nil)
  143. (defvar mail-mode-map nil)
  144.  
  145. (autoload 'build-mail-aliases "mailalias"
  146.   "Read mail aliases from user's personal aliases file and set `mail-aliases'."
  147.   nil)
  148.  
  149. (autoload 'expand-mail-aliases "mailalias"
  150.   "Expand all mail aliases in suitable header fields found between BEG and END.
  151. Suitable header fields are `To', `Cc' and `Bcc' and their `Resent-' variants.
  152. Optional second arg EXCLUDE may be a regular expression defining text to be
  153. removed from alias expansions."
  154.   nil)
  155.  
  156. ;;;###autoload
  157. (defvar mail-signature nil
  158.   "*Text inserted at end of mail buffer when a message is initialized.
  159. If t, it means to insert the contents of the file `mail-signature-file'.")
  160.  
  161. (defvar mail-signature-file "~/.signature"
  162.   "*File containing the text inserted at end of mail buffer.")
  163.  
  164. (defvar mail-reply-buffer nil)
  165. (defvar mail-send-actions nil
  166.   "A list of actions to be performed upon successful sending of a message.")
  167. (put 'mail-reply-buffer 'permanent-local t)
  168. (put 'mail-send-actions 'permanent-local t)
  169.  
  170. (defvar mail-default-headers nil
  171.   "*A string containing header lines, to be inserted in outgoing messages.
  172. It is inserted before you edit the message,
  173. so you can edit or delete these lines.")
  174.  
  175. (defvar mail-bury-selects-summary t
  176.   "*If non-nil, try to show RMAIL summary buffer after returning from mail.
  177. The functions \\[mail-send-on-exit] or \\[mail-dont-send] select
  178. the RMAIL summary buffer before returning, if it exists and this variable
  179. is non-nil.")
  180.  
  181. ;; Note: could use /usr/ucb/mail instead of sendmail;
  182. ;; options -t, and -v if not interactive.
  183. (defvar mail-mailer-swallows-blank-line
  184.   (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)" system-configuration)
  185.        (file-readable-p "/etc/sendmail.cf")
  186.        (let ((buffer (get-buffer-create " *temp*")))
  187.          (unwind-protect
  188.          (save-excursion
  189.            (set-buffer buffer)
  190.            (insert-file-contents "/etc/sendmail.cf")
  191.            (goto-char (point-min))
  192.            (let ((case-fold-search nil))
  193.              (re-search-forward "^OR\\>" nil t)))
  194.            (kill-buffer buffer))))
  195.       ;; According to RFC822, "The field-name must be composed of printable
  196.       ;; ASCII characters (i.e. characters that have decimal values between
  197.       ;; 33 and 126, except colon)", i.e. any chars except ctl chars,
  198.       ;; space, or colon.
  199.       '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
  200.   "Set this non-nil if the system's mailer runs the header and body together.
  201. \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
  202. The value should be an expression to test whether the problem will
  203. actually occur.")
  204.  
  205. (defvar mail-mode-syntax-table nil
  206.   "Syntax table used while in mail mode.")
  207.  
  208. (if (not mail-mode-syntax-table)
  209.     (progn
  210.      (setq mail-mode-syntax-table (copy-syntax-table text-mode-syntax-table))
  211.      (modify-syntax-entry ?% ". " mail-mode-syntax-table)))
  212.  
  213. (defvar mail-font-lock-keywords
  214.   (eval-when-compile
  215.     (let* ((cite-prefix "A-Za-z") (cite-suffix (concat cite-prefix "0-9_.@-")))
  216.       (list '("^To:" . font-lock-function-name-face)
  217.         '("^B?CC:\\|^Reply-to:" . font-lock-keyword-face)
  218.         '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
  219.           (1 font-lock-comment-face) (2 font-lock-type-face nil t))
  220.         '(eval cons (concat "^" (regexp-quote mail-header-separator) "$")
  221.            'font-lock-comment-face)
  222.         (cons (concat "^[ \t]*"
  223.               "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
  224.               "[>|}].*")
  225.           'font-lock-reference-face)
  226.         '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*"
  227.           . font-lock-string-face))))
  228.   "Additional expressions to highlight in Mail mode.")
  229.  
  230. (defvar mail-send-hook nil
  231.   "Normal hook run before sending mail, in Mail mode.")
  232.  
  233. (defun sendmail-sync-aliases ()
  234.   (let ((modtime (nth 5 (file-attributes mail-personal-alias-file))))
  235.     (or (equal mail-alias-modtime modtime)
  236.     (setq mail-alias-modtime modtime
  237.           mail-aliases t))))
  238.  
  239. (defun mail-setup (to subject in-reply-to cc replybuffer actions)
  240.   (or mail-default-reply-to
  241.       (setq mail-default-reply-to (getenv "REPLYTO")))
  242.   (sendmail-sync-aliases)
  243.   (if (eq mail-aliases t)
  244.       (progn
  245.     (setq mail-aliases nil)
  246.     (if (file-exists-p mail-personal-alias-file)
  247.         (build-mail-aliases))))
  248.   (setq mail-send-actions actions)
  249.   (setq mail-reply-buffer replybuffer)
  250.   (goto-char (point-min))
  251.   (insert "To: ")
  252.   (save-excursion
  253.     (if to
  254.     ;; Here removed code to extract names from within <...>
  255.     ;; on the assumption that mail-strip-quoted-names
  256.     ;; has been called and has done so.
  257.     (let ((fill-prefix "\t")
  258.           (address-start (point)))
  259.       (insert to "\n")
  260.       (fill-region-as-paragraph address-start (point-max)))
  261.       (newline))
  262.     (if cc
  263.     (let ((fill-prefix "\t")
  264.           (address-start (progn (insert "CC: ") (point))))
  265.       (insert cc "\n")
  266.       (fill-region-as-paragraph address-start (point-max))))
  267.     (if in-reply-to
  268.         (let ((fill-prefix "\t")
  269.           (fill-column 78)
  270.           (address-start (point)))
  271.       (insert "In-reply-to: " in-reply-to "\n")
  272.       (fill-region-as-paragraph address-start (point-max))))
  273.     (insert "Subject: " (or subject "") "\n")
  274.     (if mail-default-headers
  275.     (insert mail-default-headers))
  276.     (if mail-default-reply-to
  277.     (insert "Reply-to: " mail-default-reply-to "\n"))
  278.     (if mail-self-blind
  279.     (insert "BCC: " user-mail-address "\n"))
  280.     (if mail-archive-file-name
  281.     (insert "FCC: " mail-archive-file-name "\n"))
  282.     (put-text-property (point)
  283.                (progn
  284.              (insert mail-header-separator "\n")
  285.              (1- (point)))
  286.                'category 'mail-header-separator)
  287.     ;; Insert the signature.  But remember the beginning of the message.
  288.     (if to (setq to (point)))
  289.     (cond ((eq mail-signature t)
  290.        (if (file-exists-p mail-signature-file)
  291.            (progn
  292.          (insert "\n\n-- \n")
  293.          (insert-file-contents mail-signature-file))))
  294.       (mail-signature
  295.        (insert mail-signature)))
  296.     (goto-char (point-max))
  297.     (or (bolp) (newline)))
  298.   (if to (goto-char to))
  299.   (or to subject in-reply-to
  300.       (set-buffer-modified-p nil))
  301.   (run-hooks 'mail-setup-hook))
  302.  
  303. ;;;###autoload
  304. (defun mail-mode ()
  305.   "Major mode for editing mail to be sent.
  306. Like Text Mode but with these additional commands:
  307. C-c C-s  mail-send (send the message)    C-c C-c  mail-send-and-exit
  308. C-c C-f  move to a header field (and create it if there isn't):
  309.      C-c C-f C-t  move to To:    C-c C-f C-s  move to Subject:
  310.      C-c C-f C-c  move to CC:    C-c C-f C-b  move to BCC:
  311.      C-c C-f C-f  move to FCC:
  312. C-c C-t  mail-text (move to beginning of message text).
  313. C-c C-w  mail-signature (insert `mail-signature-file' file).
  314. C-c C-y  mail-yank-original (insert current message, in Rmail).
  315. C-c C-q  mail-fill-yanked-message (fill what was yanked).
  316. C-c C-v  mail-sent-via (add a Sent-via field for each To or CC)."
  317.   (interactive)
  318.   (kill-all-local-variables)
  319.   (make-local-variable 'mail-reply-buffer)
  320.   (make-local-variable 'mail-send-actions)
  321.   (set-syntax-table mail-mode-syntax-table)
  322.   (use-local-map mail-mode-map)
  323.   (setq local-abbrev-table text-mode-abbrev-table)
  324.   (setq major-mode 'mail-mode)
  325.   (setq mode-name "Mail")
  326.   (setq buffer-offer-save t)
  327.   (make-local-variable 'font-lock-defaults)
  328.   (setq font-lock-defaults '(mail-font-lock-keywords t))
  329.   (make-local-variable 'paragraph-separate)
  330.   (make-local-variable 'paragraph-start)
  331.   ;; `-- ' precedes the signature.  `-----' appears at the start of the
  332.   ;; lines that delimit forwarded messages.
  333.   ;; Lines containing just >= 3 dashes, perhaps after whitespace,
  334.   ;; are also sometimes used and should be separators.
  335.   (setq paragraph-start (concat (regexp-quote mail-header-separator)
  336.                 "$\\|[ \t]*[-_][-_][-_]+$\\|-- $\\|-----\\|"
  337.                 paragraph-start))
  338.   (setq paragraph-separate (concat (regexp-quote mail-header-separator)
  339.                    "$\\|[ \t]*[-_][-_][-_]+$\\|-- $\\|-----\\|"
  340.                    paragraph-separate))
  341.   (run-hooks 'text-mode-hook 'mail-mode-hook))
  342.  
  343. ;;; Set up keymap.
  344.  
  345. (if mail-mode-map
  346.     nil
  347.   (setq mail-mode-map (nconc (make-sparse-keymap) text-mode-map))
  348.   (define-key mail-mode-map "\M-\t" 'mail-complete)
  349.   (define-key mail-mode-map "\C-c?" 'describe-mode)
  350.   (define-key mail-mode-map "\C-c\C-f\C-t" 'mail-to)
  351.   (define-key mail-mode-map "\C-c\C-f\C-b" 'mail-bcc)
  352.   (define-key mail-mode-map "\C-c\C-f\C-f" 'mail-fcc)
  353.   (define-key mail-mode-map "\C-c\C-f\C-c" 'mail-cc)
  354.   (define-key mail-mode-map "\C-c\C-f\C-s" 'mail-subject)
  355.   (define-key mail-mode-map "\C-c\C-f\C-r" 'mail-reply-to)
  356.   (define-key mail-mode-map "\C-c\C-t" 'mail-text)
  357.   (define-key mail-mode-map "\C-c\C-y" 'mail-yank-original)
  358.   (define-key mail-mode-map "\C-c\C-q" 'mail-fill-yanked-message)
  359.   (define-key mail-mode-map "\C-c\C-w" 'mail-signature)
  360.   (define-key mail-mode-map "\C-c\C-v" 'mail-sent-via)
  361.   (define-key mail-mode-map "\C-c\C-c" 'mail-send-and-exit)
  362.   (define-key mail-mode-map "\C-c\C-s" 'mail-send))
  363.  
  364. (define-key mail-mode-map [menu-bar mail]
  365.   (cons "Mail" (make-sparse-keymap "Mail")))
  366.  
  367. (define-key mail-mode-map [menu-bar mail fill]
  368.   '("Fill Citation" . mail-fill-yanked-message))
  369.  
  370. (define-key mail-mode-map [menu-bar mail yank]
  371.   '("Cite Original" . mail-yank-original))
  372.  
  373. (define-key mail-mode-map [menu-bar mail signature]
  374.   '("Insert Signature" . mail-signature))
  375.  
  376. (define-key mail-mode-map [menu-bar mail cancel]
  377.   '("Cancel" . mail-dont-send))
  378.  
  379. (define-key mail-mode-map [menu-bar mail send-stay]
  380.   '("Send, Keep Editing" . mail-send))
  381.  
  382. (define-key mail-mode-map [menu-bar mail send]
  383.   '("Send Message" . mail-send-and-exit))
  384.  
  385. (define-key mail-mode-map [menu-bar headers]
  386.   (cons "Headers" (make-sparse-keymap "Move to Header")))
  387.  
  388. (define-key mail-mode-map [menu-bar headers reply-to]
  389.   '("Reply-To" . mail-reply-to))
  390.  
  391. (define-key mail-mode-map [menu-bar headers sent-via]
  392.   '("Sent Via" . mail-sent-via))
  393.  
  394. (define-key mail-mode-map [menu-bar headers text]
  395.   '("Text" . mail-text))
  396.  
  397. (define-key mail-mode-map [menu-bar headers bcc]
  398.   '("Bcc" . mail-bcc))
  399.  
  400. (define-key mail-mode-map [menu-bar headers fcc]
  401.   '("Fcc" . mail-fcc))
  402.  
  403. (define-key mail-mode-map [menu-bar headers cc]
  404.   '("Cc" . mail-cc))
  405.  
  406. (define-key mail-mode-map [menu-bar headers subject]
  407.   '("Subject" . mail-subject))
  408.  
  409. (define-key mail-mode-map [menu-bar headers to]
  410.   '("To" . mail-to))
  411.  
  412. (defun mail-send-and-exit (arg)
  413.   "Send message like `mail-send', then, if no errors, exit from mail buffer.
  414. Prefix arg means don't delete this window."
  415.   (interactive "P")
  416.   (mail-send)
  417.   (mail-bury arg))
  418.  
  419. (defun mail-dont-send (arg)
  420.   "Don't send the message you have been editing.
  421. Prefix arg means don't delete this window."
  422.   (interactive "P")
  423.   (mail-bury arg))
  424.  
  425. (defun mail-bury (arg)
  426.   "Bury this mail buffer."
  427.   (let ((newbuf (other-buffer (current-buffer))))
  428.     (bury-buffer (current-buffer))
  429.     (if (and (or (window-dedicated-p (frame-selected-window))
  430.          (assq 'mail-dedicated-frame (frame-parameters)))
  431.          (not (null (delq (selected-frame) (visible-frame-list)))))
  432.     (delete-frame (selected-frame))
  433.       (let (rmail-flag summary-buffer)
  434.     (and (not arg)
  435.          (not (one-window-p))
  436.          (save-excursion
  437.            (set-buffer (window-buffer (next-window (selected-window) 'not)))
  438.            (setq rmail-flag (eq major-mode 'rmail-mode))
  439.            (setq summary-buffer
  440.              (and mail-bury-selects-summary
  441.               (boundp 'rmail-summary-buffer)
  442.               rmail-summary-buffer
  443.               (buffer-name rmail-summary-buffer)
  444.               (not (get-buffer-window rmail-summary-buffer))
  445.               rmail-summary-buffer))))
  446.     (if rmail-flag
  447.         ;; If the Rmail buffer has a summary, show that.
  448.         (if summary-buffer (switch-to-buffer summary-buffer)
  449.           (delete-window))
  450.       (switch-to-buffer newbuf))))))
  451.  
  452. (defun mail-send ()
  453.   "Send the message in the current buffer.
  454. If `mail-interactive' is non-nil, wait for success indication
  455. or error messages, and inform user.
  456. Otherwise any failure is reported in a message back to
  457. the user from the mailer."
  458.   (interactive)
  459.   (if (if buffer-file-name
  460.       (y-or-n-p "Send buffer contents as mail message? ")
  461.     (or (buffer-modified-p)
  462.         (y-or-n-p "Message already sent; resend? ")))
  463.       (let ((inhibit-read-only t))
  464.     (run-hooks 'mail-send-hook)
  465.     (message "Sending...")
  466.     (funcall send-mail-function)
  467.     ;; Now perform actions on successful sending.
  468.     (while mail-send-actions
  469.       (condition-case nil
  470.           (apply (car (car mail-send-actions))
  471.              (cdr (car mail-send-actions)))
  472.         (error))
  473.       (setq mail-send-actions (cdr mail-send-actions)))
  474.     (message "Sending...done")
  475.     ;; If buffer has no file, mark it as unmodified and delete autosave.
  476.     (if (not buffer-file-name)
  477.         (progn
  478.           (set-buffer-modified-p nil)
  479.           (delete-auto-save-file-if-necessary t))))))
  480.  
  481. (defun sendmail-send-it ()
  482.   (require 'mail-utils)
  483.   (let ((errbuf (if mail-interactive
  484.             (generate-new-buffer " sendmail errors")
  485.           0))
  486.     (tembuf (generate-new-buffer " sendmail temp"))
  487.     (case-fold-search nil)
  488.     resend-to-addresses
  489.     delimline
  490.     (mailbuf (current-buffer)))
  491.     (unwind-protect
  492.     (save-excursion
  493.       (set-buffer tembuf)
  494.       (erase-buffer)
  495.       (insert-buffer-substring mailbuf)
  496.       (goto-char (point-max))
  497.       ;; require one newline at the end.
  498.       (or (= (preceding-char) ?\n)
  499.           (insert ?\n))
  500.       ;; Change header-delimiter to be what sendmail expects.
  501.       (goto-char (point-min))
  502.       (re-search-forward
  503.         (concat "^" (regexp-quote mail-header-separator) "\n"))
  504.       (replace-match "\n")
  505.       (backward-char 1)
  506.       (setq delimline (point-marker))
  507.       (sendmail-sync-aliases)
  508.       (if mail-aliases
  509.           (expand-mail-aliases (point-min) delimline))
  510.       (goto-char (point-min))
  511.       ;; ignore any blank lines in the header
  512.       (while (and (re-search-forward "\n\n\n*" delimline t)
  513.               (< (point) delimline))
  514.         (replace-match "\n"))
  515.       (let ((case-fold-search t))
  516.         (goto-char (point-min))
  517.         (while (re-search-forward "^Resent-\\(to\\|cc\\|bcc\\):" delimline t)
  518.           (setq resend-to-addresses
  519.             (save-restriction
  520.               (narrow-to-region (point)
  521.                     (save-excursion
  522.                       (end-of-line)
  523.                       (point)))
  524.               (append (mail-parse-comma-list)
  525.                   resend-to-addresses)))
  526.           ;; Delete Resent-BCC ourselves
  527.           (if (save-excursion (beginning-of-line)
  528.                   (looking-at "resent-bcc"))
  529.           (delete-region (save-excursion (beginning-of-line) (point))
  530.                  (save-excursion (end-of-line) (1+ (point))))))
  531. ;;; Apparently this causes a duplicate Sender.
  532. ;;;        ;; If the From is different than current user, insert Sender.
  533. ;;;        (goto-char (point-min))
  534. ;;;        (and (re-search-forward "^From:"  delimline t)
  535. ;;;         (progn
  536. ;;;           (require 'mail-utils)
  537. ;;;           (not (string-equal
  538. ;;;             (mail-strip-quoted-names
  539. ;;;              (save-restriction
  540. ;;;                (narrow-to-region (point-min) delimline)
  541. ;;;                (mail-fetch-field "From")))
  542. ;;;             (user-login-name))))
  543. ;;;         (progn
  544. ;;;           (forward-line 1)
  545. ;;;           (insert "Sender: " (user-login-name) "\n")))
  546.         ;; Don't send out a blank subject line
  547.         (goto-char (point-min))
  548.         (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t)
  549.         (replace-match "")
  550.           ;; This one matches a Subject just before the header delimiter.
  551.           (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t)
  552.                (= (match-end 0) delimline))
  553.           (replace-match "")))
  554.         ;; Put the "From:" field in unless for some odd reason
  555.         ;; they put one in themselves.
  556.         (goto-char (point-min))
  557.         (if (not (re-search-forward "^From:" delimline t))
  558.         (let* ((login user-mail-address)
  559.                (fullname (user-full-name)))
  560.           (cond ((eq mail-from-style 'angles)
  561.              (insert "From: " fullname)
  562.              (let ((fullname-start (+ (point-min) 6))
  563.                    (fullname-end (point-marker)))
  564.                (goto-char fullname-start)
  565.                ;; Look for a character that cannot appear unquoted
  566.                ;; according to RFC 822.
  567.                (if (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
  568.                           fullname-end 1)
  569.                    (progn
  570.                  ;; Quote fullname, escaping specials.
  571.                  (goto-char fullname-start)
  572.                  (insert "\"")
  573.                  (while (re-search-forward "[\"\\]"
  574.                                fullname-end 1)
  575.                    (replace-match "\\\\\\&" t))
  576.                  (insert "\""))))
  577.              (insert " <" login ">\n"))
  578.             ((eq mail-from-style 'parens)
  579.              (insert "From: " login " (")
  580.              (let ((fullname-start (point)))
  581.                (insert fullname)
  582.                (let ((fullname-end (point-marker)))
  583.                  (goto-char fullname-start)
  584.                  ;; RFC 822 says \ and nonmatching parentheses
  585.                  ;; must be escaped in comments.
  586.                  ;; Escape every instance of ()\ ...
  587.                  (while (re-search-forward "[()\\]" fullname-end 1)
  588.                    (replace-match "\\\\\\&" t))
  589.                  ;; ... then undo escaping of matching parentheses,
  590.                  ;; including matching nested parentheses.
  591.                  (goto-char fullname-start)
  592.                  (while (re-search-forward 
  593.                      "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
  594.                      fullname-end 1)
  595.                    (replace-match "\\1(\\3)" t)
  596.                    (goto-char fullname-start))))
  597.              (insert ")\n"))
  598.             ((null mail-from-style)
  599.              (insert "From: " login "\n")))))
  600.         ;; Insert an extra newline if we need it to work around
  601.         ;; Sun's bug that swallows newlines.
  602.         (goto-char (1+ delimline))
  603.         (if (eval mail-mailer-swallows-blank-line)
  604.         (newline))
  605.         ;; Find and handle any FCC fields.
  606.         (goto-char (point-min))
  607.         (if (re-search-forward "^FCC:" delimline t)
  608.         (mail-do-fcc delimline))
  609.         (if mail-interactive
  610.         (save-excursion
  611.           (set-buffer errbuf)
  612.           (erase-buffer))))
  613.       (let ((default-directory "/"))
  614.         (apply 'call-process-region
  615.            (append (list (point-min) (point-max)
  616.                  (if (boundp 'sendmail-program)
  617.                      sendmail-program
  618.                    "/usr/lib/sendmail")
  619.                  nil errbuf nil "-oi")
  620.                ;; Always specify who from,
  621.                ;; since some systems have broken sendmails.
  622.                (list "-f" (user-login-name))
  623. ;;;               ;; Don't say "from root" if running under su.
  624. ;;;               (and (equal (user-real-login-name) "root")
  625. ;;;                (list "-f" (user-login-name)))
  626.                (and mail-alias-file
  627.                 (list (concat "-oA" mail-alias-file)))
  628.                ;; These mean "report errors by mail"
  629.                ;; and "deliver in background".
  630.                (if (null mail-interactive) '("-oem" "-odb"))
  631.                ;; Get the addresses from the message
  632.                ;; unless this is a resend.
  633.                ;; We must not do that for a resend
  634.                ;; because we would find the original addresses.
  635.                ;; For a resend, include the specific addresses.
  636.                (or resend-to-addresses
  637.                    '("-t")))))
  638.       (if mail-interactive
  639.           (save-excursion
  640.         (set-buffer errbuf)
  641.         (goto-char (point-min))
  642.         (while (re-search-forward "\n\n* *" nil t)
  643.           (replace-match "; "))
  644.         (if (not (zerop (buffer-size)))
  645.             (error "Sending...failed to %s"
  646.                (buffer-substring (point-min) (point-max)))))))
  647.       (kill-buffer tembuf)
  648.       (if (bufferp errbuf)
  649.       (kill-buffer errbuf)))))
  650.  
  651. (defun mail-do-fcc (header-end)
  652.   (let (fcc-list
  653.     (rmailbuf (current-buffer))
  654.     (time (current-time))
  655.     (tembuf (generate-new-buffer " rmail output"))
  656.     (case-fold-search t))
  657.     (save-excursion
  658.       (goto-char (point-min))
  659.       (while (re-search-forward "^FCC:[ \t]*" header-end t)
  660.     (setq fcc-list (cons (buffer-substring (point)
  661.                            (progn
  662.                          (end-of-line)
  663.                          (skip-chars-backward " \t")
  664.                          (point)))
  665.                  fcc-list))
  666.     (delete-region (match-beginning 0)
  667.                (progn (forward-line 1) (point))))
  668.       (set-buffer tembuf)
  669.       (erase-buffer)
  670.       ;; This initial newline is written out if the fcc file already exists.
  671.       (insert "\nFrom " (user-login-name) " "
  672.           (current-time-string time) "\n")
  673.       ;; Insert the time zone before the year.
  674.       (forward-char -1)
  675.       (forward-word -1)
  676.       (require 'mail-utils)
  677.       (insert (mail-rfc822-time-zone time) " ")
  678.       (goto-char (point-max))
  679.       (insert-buffer-substring rmailbuf)
  680.       ;; Make sure messages are separated.
  681.       (goto-char (point-max))
  682.       (insert ?\n)
  683.       (goto-char 2)
  684.       ;; ``Quote'' "^From " as ">From "
  685.       ;;  (note that this isn't really quoting, as there is no requirement
  686.       ;;   that "^[>]+From " be quoted in the same transparent way.)
  687.       (let ((case-fold-search nil))
  688.     (while (search-forward "\nFrom " nil t)
  689.       (forward-char -5)
  690.       (insert ?>)))
  691.       (while fcc-list
  692.     (let* ((buffer (find-buffer-visiting (car fcc-list)))
  693.            (curbuf (current-buffer))
  694.            (beg (point-min)) (end (point-max))
  695.            (beg2 (save-excursion (goto-char (point-min))
  696.                      (forward-line 2) (point))))
  697.       (if buffer
  698.           ;; File is present in a buffer => append to that buffer.
  699.           (save-excursion
  700.         (set-buffer buffer)
  701.         ;; Keep the end of the accessible portion at the same place
  702.         ;; unless it is the end of the buffer.
  703.         (let ((max (if (/= (1+ (buffer-size)) (point-max))
  704.                    (point-max))))
  705.           (unwind-protect
  706.               ;; Code below lifted from rmailout.el
  707.               ;; function rmail-output-to-rmail-file:
  708.               (let ((buffer-read-only nil)
  709.                 (msg (and (boundp 'rmail-current-message)
  710.                       rmail-current-message)))
  711.             ;; If MSG is non-nil, buffer is in RMAIL mode.
  712.             (if msg
  713.                 (progn
  714.                   (rmail-maybe-set-message-counters)
  715.                   (widen)
  716.                   (narrow-to-region (point-max) (point-max))
  717.                   (insert "\C-l\n0, unseen,,\n*** EOOH ***\n"
  718.                       "Date: " (mail-rfc822-date) "\n")
  719.                   (insert-buffer-substring curbuf beg2 end)
  720.                   (insert "\n\C-_")
  721.                   (goto-char (point-min))
  722.                   (widen)
  723.                   (search-backward "\n\^_")
  724.                   (narrow-to-region (point) (point-max))
  725.                   (rmail-count-new-messages t)
  726.                   (rmail-show-message msg)
  727.                   (setq max nil))
  728.               ;; Output file not in rmail mode
  729.               ;; => just insert at the end.
  730.               (narrow-to-region (point-min) (1+ (buffer-size)))
  731.               (goto-char (point-max))
  732.               (insert-buffer-substring curbuf beg end)))
  733.             (if max (narrow-to-region (point-min) max)))))
  734.         ;; Else append to the file directly.
  735.         (if (and (file-exists-p (car fcc-list))
  736.              (mail-file-babyl-p (car fcc-list)))
  737.         ;; If the file is a Babyl file,
  738.         ;; convert the message to Babyl format.
  739.         (save-excursion
  740.           (set-buffer (get-buffer-create " mail-temp"))
  741.           (setq buffer-read-only nil)
  742.           (erase-buffer)
  743.           (insert "\C-l\n0, unseen,,\n*** EOOH ***\n"
  744.               "Date: " (mail-rfc822-date) "\n")
  745.           (insert-buffer-substring curbuf beg2 end)
  746.           (insert "\n\C-_")
  747.           (write-region (point-min) (point-max) (car fcc-list) t)
  748.           (erase-buffer))
  749.           (write-region
  750.            (1+ (point-min)) (point-max) (car fcc-list) t))))
  751.     (setq fcc-list (cdr fcc-list))))
  752.     (kill-buffer tembuf)))
  753.  
  754. (defun mail-sent-via ()
  755.   "Make a Sent-via header line from each To or CC header line."
  756.   (interactive)
  757.   (save-excursion
  758.     (goto-char (point-min))
  759.     ;; find the header-separator
  760.     (search-forward (concat "\n" mail-header-separator "\n"))
  761.     (forward-line -1)
  762.     ;; put a marker at the end of the header
  763.     (let ((end (point-marker))
  764.       (case-fold-search t)
  765.       to-line)
  766.       (goto-char (point-min))
  767.       ;; search for the To: lines and make Sent-via: lines from them
  768.       ;; search for the next To: line
  769.       (while (re-search-forward "^\\(to\\|cc\\):" end t)
  770.     ;; Grab this line plus all its continuations, sans the `to:'.
  771.     (let ((to-line
  772.            (buffer-substring (point)
  773.                  (progn
  774.                    (if (re-search-forward "^[^ \t\n]" end t)
  775.                        (backward-char 1)
  776.                      (goto-char end))
  777.                    (point)))))
  778.       ;; Insert a copy, with altered header field name.
  779.       (insert-before-markers "Sent-via:" to-line))))))
  780.  
  781. (defun mail-to ()
  782.   "Move point to end of To-field."
  783.   (interactive)
  784.   (expand-abbrev)
  785.   (mail-position-on-field "To"))
  786.  
  787. (defun mail-subject ()
  788.   "Move point to end of Subject-field."
  789.   (interactive)
  790.   (expand-abbrev)
  791.   (mail-position-on-field "Subject"))
  792.  
  793. (defun mail-cc ()
  794.   "Move point to end of CC-field.  Create a CC field if none."
  795.   (interactive)
  796.   (expand-abbrev)
  797.   (or (mail-position-on-field "cc" t)
  798.       (progn (mail-position-on-field "to")
  799.          (insert "\nCC: "))))
  800.  
  801. (defun mail-bcc ()
  802.   "Move point to end of BCC-field.  Create a BCC field if none."
  803.   (interactive)
  804.   (expand-abbrev)
  805.   (or (mail-position-on-field "bcc" t)
  806.       (progn (mail-position-on-field "to")
  807.          (insert "\nBCC: "))))
  808.  
  809. (defun mail-fcc (folder)
  810.   "Add a new FCC field, with file name completion."
  811.   (interactive "FFolder carbon copy: ")
  812.   (expand-abbrev)
  813.   (or (mail-position-on-field "fcc" t)    ;Put new field after exiting FCC.
  814.       (mail-position-on-field "to"))
  815.   (insert "\nFCC: " folder))
  816.  
  817. (defun mail-reply-to ()      
  818.   "Move point to end of Reply-To-field."
  819.   (interactive)
  820.   (expand-abbrev)
  821.   (mail-position-on-field "Reply-To"))
  822.  
  823. (defun mail-position-on-field (field &optional soft)
  824.   (let (end
  825.     (case-fold-search t))
  826.     (goto-char (point-min))
  827.     (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
  828.     (setq end (match-beginning 0))
  829.     (goto-char (point-min))
  830.     (if (re-search-forward (concat "^" (regexp-quote field) ":") end t)
  831.     (progn
  832.       (re-search-forward "^[^ \t]" nil 'move)
  833.       (beginning-of-line)
  834.       (skip-chars-backward "\n")
  835.       t)
  836.       (or soft
  837.       (progn (goto-char end)
  838.          (insert field ": \n")
  839.          (skip-chars-backward "\n")))
  840.       nil)))
  841.  
  842. (defun mail-text ()
  843.   "Move point to beginning of message text."
  844.   (interactive)
  845.   (expand-abbrev)
  846.   (goto-char (point-min))
  847.   (search-forward (concat "\n" mail-header-separator "\n")))
  848.  
  849. (defun mail-signature (atpoint)
  850.   "Sign letter with contents of the file `mail-signature-file'.
  851. Prefix arg means put contents at point."
  852.   (interactive "P")
  853.   (save-excursion
  854.     (or atpoint
  855.     (goto-char (point-max)))
  856.     (skip-chars-backward " \t\n")
  857.     (end-of-line)
  858.     (or atpoint
  859.     (delete-region (point) (point-max)))
  860.     (insert "\n\n-- \n")
  861.     (insert-file-contents (expand-file-name mail-signature-file))))
  862.  
  863. (defun mail-fill-yanked-message (&optional justifyp)
  864.   "Fill the paragraphs of a message yanked into this one.
  865. Numeric argument means justify as well."
  866.   (interactive "P")
  867.   (save-excursion
  868.     (goto-char (point-min))
  869.     (search-forward (concat "\n" mail-header-separator "\n") nil t)
  870.     (fill-individual-paragraphs (point)
  871.                 (point-max)
  872.                 justifyp
  873.                 t)))
  874.  
  875. (defun mail-indent-citation ()
  876.   "Modify text just inserted from a message to be cited.
  877. The inserted text should be the region.
  878. When this function returns, the region is again around the modified text.
  879.  
  880. Normally, indent each nonblank line `mail-indentation-spaces' spaces.
  881. However, if `mail-yank-prefix' is non-nil, insert that prefix on each line."
  882.   (let ((start (point)))
  883.     (mail-yank-clear-headers start (mark t))
  884.     (if (null mail-yank-prefix)
  885.     (indent-rigidly start (mark t) mail-indentation-spaces)
  886.       (save-excursion
  887.     (goto-char start)
  888.     (while (< (point) (mark t))
  889.       (insert mail-yank-prefix)
  890.       (forward-line 1))))))
  891.  
  892. (defun mail-yank-original (arg)
  893.   "Insert the message being replied to, if any (in rmail).
  894. Puts point after the text and mark before.
  895. Normally, indents each nonblank line ARG spaces (default 3).
  896. However, if `mail-yank-prefix' is non-nil, insert that prefix on each line.
  897.  
  898. Just \\[universal-argument] as argument means don't indent, insert no prefix,
  899. and don't delete any header fields."
  900.   (interactive "P")
  901.   (if mail-reply-buffer
  902.       (let ((start (point)))
  903.     ;; If the original message is in another window in the same frame,
  904.     ;; delete that window to save screen space.
  905.     ;; t means don't alter other frames.
  906.     (delete-windows-on mail-reply-buffer t)
  907.     (insert-buffer mail-reply-buffer)
  908.     (if (consp arg)
  909.         nil
  910.       (goto-char start)
  911.       (let ((mail-indentation-spaces (if arg (prefix-numeric-value arg)
  912.                        mail-indentation-spaces)))
  913.         (if mail-citation-hook
  914.         (run-hooks 'mail-citation-hook)
  915.           (if mail-yank-hooks
  916.           (run-hooks 'mail-yank-hooks)
  917.         (mail-indent-citation)))))
  918.     ;; This is like exchange-point-and-mark, but doesn't activate the mark.
  919.     ;; It is cleaner to avoid activation, even though the command
  920.     ;; loop would deactivate the mark because we inserted text.
  921.     (goto-char (prog1 (mark t)
  922.              (set-marker (mark-marker) (point) (current-buffer))))
  923.     (if (not (eolp)) (insert ?\n)))))
  924.  
  925. (defun mail-yank-clear-headers (start end)
  926.   (if mail-yank-ignored-headers
  927.       (save-excursion
  928.     (goto-char start)
  929.     (if (search-forward "\n\n" end t)
  930.         (save-restriction
  931.           (narrow-to-region start (point))
  932.           (goto-char start)
  933.           (while (let ((case-fold-search t))
  934.                (re-search-forward mail-yank-ignored-headers nil t))
  935.         (beginning-of-line)
  936.         (delete-region (point)
  937.                    (progn (re-search-forward "\n[^ \t]")
  938.                       (forward-char -1)
  939.                       (point)))))))))
  940.  
  941. ;; Put these last, to reduce chance of lossage from quitting in middle of loading the file.
  942.  
  943. ;;;###autoload
  944. (defun mail (&optional noerase to subject in-reply-to cc replybuffer actions)
  945.   "Edit a message to be sent.  Prefix arg means resume editing (don't erase).
  946. When this function returns, the buffer `*mail*' is selected.
  947. The value is t if the message was newly initialized; otherwise, nil.
  948.  
  949. Optionally, the signature file `mail-signature-file' can be inserted at the
  950. end; see the variable `mail-signature'.
  951.  
  952. \\<mail-mode-map>
  953. While editing message, type \\[mail-send-and-exit] to send the message and exit.
  954.  
  955. Various special commands starting with C-c are available in sendmail mode
  956. to move to message header fields:
  957. \\{mail-mode-map}
  958.  
  959. If `mail-self-blind' is non-nil, a BCC to yourself is inserted
  960. when the message is initialized.
  961.  
  962. If `mail-default-reply-to' is non-nil, it should be an address (a string);
  963. a Reply-to: field with that address is inserted.
  964.  
  965. If `mail-archive-file-name' is non-nil, an FCC field with that file name
  966. is inserted.
  967.  
  968. The normal hook `mail-setup-hook' is run after the message is
  969. initialized.  It can add more default fields to the message.
  970.  
  971. When calling from a program, the first argument if non-nil says
  972. not to erase the existing contents of the `*mail*' buffer.
  973.  
  974. The second through fifth arguments,
  975.  TO, SUBJECT, IN-REPLY-TO and CC, specify if non-nil
  976.  the initial contents of those header fields.
  977.  These arguments should not have final newlines.
  978. The sixth argument REPLYBUFFER is a buffer whose contents
  979.  should be yanked if the user types C-c C-y.
  980. The seventh argument ACTIONS is a list of actions to take
  981.  if/when the message is sent.  Each action looks like (FUNCTION . ARGS);
  982.  when the message is sent, we apply FUNCTION to ARGS.
  983.  This is how Rmail arranges to mark messages `answered'."
  984.   (interactive "P")
  985. ;;; This is commented out because I found it was confusing in practice.
  986. ;;; It is easy enough to rename *mail* by hand with rename-buffer
  987. ;;; if you want to have multiple mail buffers.
  988. ;;; And then you can control which messages to save. --rms.
  989. ;;;  (let ((index 1)
  990. ;;;    buffer)
  991. ;;;    ;; If requested, look for a mail buffer that is modified and go to it.
  992. ;;;    (if noerase
  993. ;;;    (progn
  994. ;;;      (while (and (setq buffer
  995. ;;;                (get-buffer (if (= 1 index) "*mail*"
  996. ;;;                      (format "*mail*<%d>" index))))
  997. ;;;              (not (buffer-modified-p buffer)))
  998. ;;;        (setq index (1+ index)))
  999. ;;;      (if buffer (switch-to-buffer buffer)
  1000. ;;;        ;; If none exists, start a new message.
  1001. ;;;        ;; This will never re-use an existing unmodified mail buffer
  1002. ;;;        ;; (since index is not 1 anymore).  Perhaps it should.
  1003. ;;;        (setq noerase nil))))
  1004. ;;;    ;; Unless we found a modified message and are happy, start a new message.
  1005. ;;;    (if (not noerase)
  1006. ;;;    (progn
  1007. ;;;      ;; Look for existing unmodified mail buffer.
  1008. ;;;      (while (and (setq buffer
  1009. ;;;                (get-buffer (if (= 1 index) "*mail*"
  1010. ;;;                      (format "*mail*<%d>" index))))
  1011. ;;;              (buffer-modified-p buffer))
  1012. ;;;        (setq index (1+ index)))
  1013. ;;;      ;; If none, make a new one.
  1014. ;;;      (or buffer
  1015. ;;;          (setq buffer (generate-new-buffer "*mail*")))
  1016. ;;;      ;; Go there and initialize it.
  1017. ;;;      (switch-to-buffer buffer)
  1018. ;;;      (erase-buffer)
  1019. ;;;          (setq default-directory (expand-file-name "~/"))
  1020. ;;;          (auto-save-mode auto-save-default)
  1021. ;;;          (mail-mode)
  1022. ;;;          (mail-setup to subject in-reply-to cc replybuffer actions)
  1023. ;;;      (if (and buffer-auto-save-file-name
  1024. ;;;           (file-exists-p buffer-auto-save-file-name))
  1025. ;;;          (message "Auto save file for draft message exists; consider M-x mail-recover"))
  1026. ;;;          t))
  1027.   (pop-to-buffer "*mail*")
  1028.   ;; Put the auto-save file in the home dir
  1029.   ;; to avoid any danger that it can't be written.
  1030.   (if (file-exists-p (expand-file-name "~/"))
  1031.       (setq default-directory (expand-file-name "~/")))
  1032.   (auto-save-mode auto-save-default)
  1033.   (mail-mode)
  1034.   ;; Disconnect the buffer from its visited file
  1035.   ;; (in case the user has actually visited a file *mail*).
  1036. ;  (set-visited-file-name nil)
  1037.   (let (initialized)
  1038.     (and (not noerase)
  1039.      (or (not (buffer-modified-p))
  1040.          (y-or-n-p "Unsent message being composed; erase it? "))
  1041.      (let ((inhibit-read-only t))
  1042.        (erase-buffer)
  1043.        (mail-setup to subject in-reply-to cc replybuffer actions)
  1044.        (setq initialized t)))
  1045.     (if (and buffer-auto-save-file-name
  1046.          (file-exists-p buffer-auto-save-file-name))
  1047.     (message "Auto save file for draft message exists; consider M-x mail-recover"))
  1048.     initialized))
  1049.  
  1050. (defun mail-recover ()
  1051.   "Reread contents of current buffer from its last auto-save file."
  1052.   (interactive)
  1053.   (let ((file-name (make-auto-save-file-name)))
  1054.     (cond ((save-window-excursion
  1055.          (if (not (eq system-type 'vax-vms))
  1056.          (with-output-to-temp-buffer "*Directory*"
  1057.            (buffer-disable-undo standard-output)
  1058.            (let ((default-directory "/"))
  1059.              (call-process
  1060.               "ls" nil standard-output nil "-l" file-name))))
  1061.          (yes-or-no-p (format "Recover auto save file %s? " file-name)))
  1062.        (let ((buffer-read-only nil))
  1063.          (erase-buffer)
  1064.          (insert-file-contents file-name nil)))
  1065.       (t (error "mail-recover cancelled")))))
  1066.  
  1067. ;;;###autoload
  1068. (defun mail-other-window (&optional noerase to subject in-reply-to cc replybuffer sendactions)
  1069.   "Like `mail' command, but display mail buffer in another window."
  1070.   (interactive "P")
  1071.   (let ((pop-up-windows t)
  1072.     (special-display-buffer-names nil)
  1073.     (special-display-regexps nil)
  1074.     (same-window-buffer-names nil)
  1075.     (same-window-regexps nil))
  1076.     (pop-to-buffer "*mail*"))
  1077.   (mail noerase to subject in-reply-to cc replybuffer sendactions))
  1078.  
  1079. ;;;###autoload
  1080. (defun mail-other-frame (&optional noerase to subject in-reply-to cc replybuffer sendactions)
  1081.   "Like `mail' command, but display mail buffer in another frame."
  1082.   (interactive "P")
  1083.   (let ((pop-up-frames t)
  1084.     (special-display-buffer-names nil)
  1085.     (special-display-regexps nil)
  1086.     (same-window-buffer-names nil)
  1087.     (same-window-regexps nil))
  1088.     (pop-to-buffer "*mail*"))
  1089.   (mail noerase to subject in-reply-to cc replybuffer sendactions))
  1090.  
  1091. ;;; Do not execute these when sendmail.el is loaded,
  1092. ;;; only in loaddefs.el.
  1093. ;;;###autoload (define-key ctl-x-map "m" 'mail)
  1094. ;;;###autoload (define-key ctl-x-4-map "m" 'mail-other-window)
  1095. ;;;###autoload (define-key ctl-x-5-map "m" 'mail-other-frame)
  1096.  
  1097. ;;;###autoload (add-hook 'same-window-buffer-names "*mail*")
  1098.  
  1099. ;;; Do not add anything but external entries on this page.
  1100.  
  1101. (provide 'sendmail)
  1102.  
  1103. ;;; sendmail.el ends here
  1104.